<template>
  <div class="app-container">
    <div style="display: inline-block;margin-bottom:15px">
      <label class="radio-label" style="padding-left: 0">钱包地址: </label>
      <el-input
        v-model="address"
        placeholder="钱包地址"
        style="width: 345px;margin-right:10px"
      />
      <el-button type="primary" @click="fetchData">搜索</el-button>
    </div>
    <el-table
      :data="list"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="币种" width="95">
        <template>
          TDeFiOS
        </template>
      </el-table-column>
      <el-table-column label="数量">
        <template slot-scope="scope">
          {{ scope.row.fodAmount }}
        </template>
      </el-table-column>
      <el-table-column label="质押笔数" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.investAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="质押时长" width="110" align="center">
        <template slot-scope="scope">
          {{ datedifference(scope.row.createTime,scope.row.dueTime) }}天
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getAllPledge } from "@/api/index";
import { getLockAddr } from "@/api/index";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      list: null,
      address:'',
    };
  },
  created() {

  },
  methods: {
    datedifference(sDate1, sDate2) { 
        let dateSpan,
            tempDate,
            iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        console.log(sDate1,sDate2)
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
    },
    fetchData() {
      getAllPledge({
        address:this.address
      }).then(res => {
        this.list = res.data;
      })
    },
  },
};
</script>
